package com.hightemperator.util;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class SendVerificodeUtil {
    private static Log log = LogFactory.getLog(SendVerificodeUtil.class);
    static final String product = "Dysmsapi";
    static final String domain = "dysmsapi.aliyuncs.com";

    static final String accessKeyId = Constant.ALI_APP_KEY;
    static final String accessKeySecret = Constant.ALI_APP_SECRET;

    public static void sendVerificode(String mobile, String code) {
        try {
            IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
            DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
            IAcsClient acsClient = new DefaultAcsClient(profile);

            SendSmsRequest request = new SendSmsRequest();
            request.setPhoneNumbers(mobile);
            request.setSignName(Constant.ALI_SIGN_NAME);
            request.setTemplateCode(Constant.ALI_SMS_TEMPLATE_CODE);
            request.setTemplateParam("{code:'" + code + "'}");

            acsClient.getAcsResponse(request);
        } catch (Exception e) {
            log.debug("短信发送异常: " + e.getMessage());
        }

    }


}
